
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/20/2011 14:25:54
-- Generated from EDMX file: D:\Code\FPP\FPP\Models\FamousPeopleModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [fppadmin];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_FamousPersonPool]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Pools] DROP CONSTRAINT [FK_FamousPersonPool];
GO
IF OBJECT_ID(N'[dbo].[FK_PoolTypePool]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Pools] DROP CONSTRAINT [FK_PoolTypePool];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPool]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Pools] DROP CONSTRAINT [FK_UserPool];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FamousPersons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FamousPersons];
GO
IF OBJECT_ID(N'[dbo].[News]', 'U') IS NOT NULL
    DROP TABLE [dbo].[News];
GO
IF OBJECT_ID(N'[dbo].[Pools]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Pools];
GO
IF OBJECT_ID(N'[dbo].[PoolTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PoolTypes];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[WikiLinks]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WikiLinks];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'FamousPersons'
CREATE TABLE [dbo].[FamousPersons] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DisplayName] nvarchar(max)  NOT NULL,
    [DateOfBirth] datetime  NOT NULL,
    [DateOfDeath] datetime  NULL,
    [WikiLink] nvarchar(max)  NULL
);
GO

-- Creating table 'Pools'
CREATE TABLE [dbo].[Pools] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [PoolTypeId] int  NOT NULL,
    [FamousPersonId] int  NOT NULL,
    [DateCreated] datetime  NOT NULL
);
GO

-- Creating table 'PoolTypes'
CREATE TABLE [dbo].[PoolTypes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [NumOfPeople] nvarchar(max)  NOT NULL,
    [NumOfAlts] nvarchar(max)  NOT NULL,
    [WinRule] nvarchar(max)  NOT NULL,
    [WinMultiplier] nvarchar(max)  NOT NULL,
    [DateStart] nvarchar(max)  NOT NULL,
    [DateEnd] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [MiddleName] nvarchar(max)  NULL,
    [Suffix] nvarchar(max)  NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [LoginToken] nvarchar(max)  NULL,
    [LoginExp] datetime  NULL,
    [role] nvarchar(50)  NULL
);
GO

-- Creating table 'WikiLinks'
CREATE TABLE [dbo].[WikiLinks] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Link] nvarchar(500)  NOT NULL,
    [DOB] nvarchar(50)  NULL,
    [ImageUrl] nvarchar(500)  NULL,
    [modDateTime] nvarchar(50)  NULL,
    [DisplayName] nvarchar(max)  NULL,
    [DOD] nvarchar(50)  NULL
);
GO

-- Creating table 'News'
CREATE TABLE [dbo].[News] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] varchar(160)  NULL,
    [Body] varchar(max)  NULL,
    [DateOfNews] datetime  NULL,
    [SourceUrl] varchar(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'FamousPersons'
ALTER TABLE [dbo].[FamousPersons]
ADD CONSTRAINT [PK_FamousPersons]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Pools'
ALTER TABLE [dbo].[Pools]
ADD CONSTRAINT [PK_Pools]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PoolTypes'
ALTER TABLE [dbo].[PoolTypes]
ADD CONSTRAINT [PK_PoolTypes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'WikiLinks'
ALTER TABLE [dbo].[WikiLinks]
ADD CONSTRAINT [PK_WikiLinks]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'News'
ALTER TABLE [dbo].[News]
ADD CONSTRAINT [PK_News]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [FamousPersonId] in table 'Pools'
ALTER TABLE [dbo].[Pools]
ADD CONSTRAINT [FK_FamousPersonPool]
    FOREIGN KEY ([FamousPersonId])
    REFERENCES [dbo].[FamousPersons]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FamousPersonPool'
CREATE INDEX [IX_FK_FamousPersonPool]
ON [dbo].[Pools]
    ([FamousPersonId]);
GO

-- Creating foreign key on [PoolTypeId] in table 'Pools'
ALTER TABLE [dbo].[Pools]
ADD CONSTRAINT [FK_PoolTypePool]
    FOREIGN KEY ([PoolTypeId])
    REFERENCES [dbo].[PoolTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PoolTypePool'
CREATE INDEX [IX_FK_PoolTypePool]
ON [dbo].[Pools]
    ([PoolTypeId]);
GO

-- Creating foreign key on [UserId] in table 'Pools'
ALTER TABLE [dbo].[Pools]
ADD CONSTRAINT [FK_UserPool]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPool'
CREATE INDEX [IX_FK_UserPool]
ON [dbo].[Pools]
    ([UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------